package cc.vv.btpartyjob.partymanager.activity

import android.content.Intent
import android.text.TextUtils
import android.view.View
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.jnimodule.globle.IntentJniKey
import cc.vv.btpartyjob.jnimodule.server.JniStartActivity
import cc.vv.btpartyjob.jnimodule.server.UserRoleServer
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.delegate.FourTeamsActivityDelegate
import cc.vv.btpartyjob.partymanager.delegate.ManagerBaseBinder
import cc.vv.btpartyjob.partymanager.moudel.resp.GetCurrentFuPingResponseObj
import cc.vv.btpartyjob.partymanager.server.PartyManagerServer
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder

/**
 * 四支队伍(第一书记)
 * Created by Chen.qi on 2018/10/27.
 */
class FourTeamsActivity : BaseActivityMVP<FourTeamsActivityDelegate>() {

    private var id: String? = null


    override fun initData() {
        val areaRole = UserRoleServer.getAreaRole()
        viewDelegate?.showRight(areaRole)
        if (areaRole) {
            JniStartActivity.startIntentCun(this@FourTeamsActivity,
                    2, 100)
        } else {
            PartyManagerServer.getCurrentFuPingCunInfo()
        }
    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
                JniStartActivity.startIntentCun(this@FourTeamsActivity,
                        2, 100)
            }
        })

        viewDelegate?.setOnClickListener(View.OnClickListener {
            //第一书记
            if (!TextUtils.isEmpty(id)) {
                val intent = Intent(this, DiYiShuJiActivity::class.java)
                intent.putExtra("id", id)
                startActivity(intent)
            }
        }, R.id.ll_aftV_firstSecretary)


        viewDelegate?.setOnClickListener(View.OnClickListener {
            //扶贫工作队
            if (!TextUtils.isEmpty(id)) {
                val intent = Intent(this, WorkTeamActivity::class.java)
                intent.putExtra("id", id)
                intent.putExtra("type", 2)
                startActivity(intent)
            }
        }, R.id.ll_aftV_fuPingTeam)

        viewDelegate?.setOnClickListener(View.OnClickListener {
            //驻村干部
            if (!TextUtils.isEmpty(id)) {
                val intent = Intent(this, WorkTeamActivity::class.java)
                intent.putExtra("id", id)
                intent.putExtra("type", 3)
                startActivity(intent)
            }
        }, R.id.ll_aftV_zhuCunOur)

        viewDelegate?.setOnClickListener(View.OnClickListener {
            //村两委班子
            if (!TextUtils.isEmpty(id)) {
                val intent = Intent(this, WorkTeamActivity::class.java)
                intent.putExtra("id", id)
                intent.putExtra("type", 1)
                startActivity(intent)
            }
        }, R.id.ll_aftV_cunBanZi)
    }

    override fun getDelegateClass(): Class<FourTeamsActivityDelegate> {
        return FourTeamsActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return ManagerBaseBinder()
    }

    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
            is GetCurrentFuPingResponseObj -> {
                val data = obj.data
                viewDelegate?.setTopBarTitle(data?.villageName)
                id = data?.id
            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (null == data) {
            if (TextUtils.isEmpty(id)) {
                finish()
            }
            return
        }
        if (requestCode == 100 && resultCode == 101) {
            id = data.getStringExtra(IntentJniKey.INTENT_KEY_ORGAN_ID)
            val cunName = data.getStringExtra(IntentJniKey.INTENT_KEY_ORGAN_NAME)
            viewDelegate?.setTopBarTitle(cunName)
        }
    }

}